﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SistemaGO_Library.Entidades.Usuario;
using SistemaGO_Desktop.Visao.Telas;
using SistemaGO_Library;

namespace SistemaGO_Desktop.Visao.Telas
{
    public partial class frmPrincipal : Form
    {
        private static frmPrincipal instancia = null;
        Fachada fachada = Fachada.getInstance();
        public Usuario usuario;
        public int MasterCode;

        private frmPrincipal(Usuario usu)
        {
            InitializeComponent();
            timer1.Enabled = true;
            toolStripLabel1.Text = DateTime.Now.ToString();
            toolStripLabel2.Text = "Bem-Vindo " + usu.Usu_nome;
            if (usu.Usu_prioridade == "A") {
                this.sistemaToolStripMenuItem.Visible = true;
            } else if (usu.Usu_prioridade == "O") {
                this.sistemaToolStripMenuItem.Visible = false;
            }
        }

        public static frmPrincipal getInstance(Usuario usu) {
            if (instancia == null) {
                instancia = new frmPrincipal(usu);
            } else {
                instancia.Focus();
            }
            return instancia;
        }

        private void btAdicionar_Click(object sender, EventArgs e) {
            frmAdicionarOcorrencia frmadicionarocorrencia = frmAdicionarOcorrencia.getInstance();
            frmadicionarocorrencia.Show();
        }

        private void btVerificar_Click(object sender, EventArgs e) {
            frmVerificarOcorrencias frmverificarocorrencias = frmVerificarOcorrencias.getInstance();
            frmverificarocorrencias.Show();
        }

        private void usuariosToolStripMenuItem_Click(object sender, EventArgs e) {
            frmUsuarios frmusuarios = frmUsuarios.getInstance();
            frmusuarios.Show();
        }

        private void terceirosToolStripMenuItem_Click(object sender, EventArgs e) {
            frmTerceiros frmterceiros = frmTerceiros.getInstance();
            frmterceiros.Show();
        }

        private void categoriaToolStripMenuItem_Click(object sender, EventArgs e) {
            frmCategorias frmcategorias = frmCategorias.getInstance();
            frmcategorias.Show();
        }

        private void opçõesToolStripMenuItem_Click(object sender, EventArgs e) {
            frmOpcoes frmopcoes = frmOpcoes.getInstance();
            frmopcoes.Show();
        }

        private void deslogarToolStripMenuItem_Click(object sender, EventArgs e) {
            DialogResult resultado = MessageBox.Show("Você tem certeza que quer deslogar?", "Deslogar", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (resultado == System.Windows.Forms.DialogResult.Yes) {
                fachada.registrarLogoffUsuario(DateTime.Now, MasterCode);
                this.Dispose();
                instancia = null;
                Application.Exit();
            }
        }

        private void adicionarToolStripMenuItem_Click(object sender, EventArgs e) {
            frmAdicionarOcorrencia frmadicionarocorrencia = frmAdicionarOcorrencia.getInstance();
            frmadicionarocorrencia.Show();
        }

        private void verificarToolStripMenuItem_Click(object sender, EventArgs e) {
            frmVerificarOcorrencias frmverificarocorrencias = frmVerificarOcorrencias.getInstance();
            frmverificarocorrencias.Show();
        }

        private void usuáriosToolStripMenuItem_Click(object sender, EventArgs e) {
            frmRelatorioUsuarios frmrelatoriousuarios = frmRelatorioUsuarios.getInstance();
            frmrelatoriousuarios.Show();
        }

        private void terceirosToolStripMenuItem1_Click(object sender, EventArgs e) {
            frmRelatorioTerceiros frmrelatorioterceiros = frmRelatorioTerceiros.getInstance();
            frmrelatorioterceiros.Show();
        }

        private void ocorrênciasToolStripMenuItem_Click(object sender, EventArgs e) {
            frmRelatorioOcorrencias frmrelatorioocorrencias = frmRelatorioOcorrencias.getInstance();
            frmrelatorioocorrencias.Show();
        }

        private void manualDoUsuárioToolStripMenuItem_Click(object sender, EventArgs e) {
            System.Diagnostics.Process.Start(@"C:\Documents and Settings\henrique\Desktop\abc.pdf");
        }

        private void sobreToolStripMenuItem_Click(object sender, EventArgs e) {
            frmSobre frmsobre = frmSobre.getInstance();
            frmsobre.Show();
        }

        private void frmPrincipal_FormClosing(object sender, FormClosingEventArgs e) {
            DialogResult resultado = MessageBox.Show("Você tem certeza que quer deslogar?", "Deslogar", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (resultado == System.Windows.Forms.DialogResult.No) {
                e.Cancel = true;
            } else {
                fachada.registrarLogoffUsuario(DateTime.Now, MasterCode);
                this.Dispose();
                instancia = null;
                Application.Exit();
            }
        }

        private void timer1_Tick(object sender, EventArgs e) {
            toolStripLabel1.Text = DateTime.Now.ToString();
        }
    }
}
